package com.duobaoyu.dby.supply.biz.client.boundary.channel;

import com.duobaoyu.dby.channel.adapter.bean.logistics.ExpressInfo;
import com.duobaoyu.dby.channel.adapter.bean.logistics.LogisticsTrackInfo;
import com.duobaoyu.dby.channel.adapter.service.AbstractSupplyLogisticsService;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceApiClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.bo.ExpressInfoBO;
import com.duobaoyu.dby.supply.biz.client.resource.converter.ResourceConverter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 渠道工具客户端
 * @author chenms
 * @date 2023/11/27 9:25 AM
 */
@Component
@RequiredArgsConstructor
public class SupplyChainLogisticsService extends AbstractSupplyLogisticsService {

	private final ResourceConverter resourceConverter;
	private final ResourceApiClient resourceApiClient;

	@Override
	public ExpressInfo getExpressInfo(String channelCode,String channelExpressCode) {
		Map<String, ExpressInfoBO> expressInfoAllCacheByChannelCode = resourceApiClient.getExpressInfoAllCacheByChannelCode(channelCode);
		ExpressInfoBO expressInfoBO = expressInfoAllCacheByChannelCode.get(channelExpressCode);
		return resourceConverter.toExpressInfo(expressInfoBO);
	}

	@Override
	public LogisticsTrackInfo getLogisticsTrackInfo(String deliveryOrderSn, String expressCompanyCode, String phone) {
		return resourceApiClient.getLogisticsTrack(deliveryOrderSn,expressCompanyCode,phone);
	}
}
